<template>
   <div class="commonlist">
        <div class="list_title">
            <div class="title" :style="type===2?'color:#fff;box-sizing:border-box;padding-left:20px;background:url(/static/images/t_bg.png) no-repeat center center':''">{{name}}</div>
            <div class="more">
                <a :href="url">
                    [查看更多]
                </a>
            </div>
        </div>
        <ul class="news_list" v-if="list.length>0">
            <li class="news_item" v-for="item in list" :key="item.id">
                <a :href="'#/detail?id='+item.id+'&name='+name+'&url='+url" v-if="sort === 1&&name!='榜样力量'">
                    <div class="left_title">
                        <div class="point"></div>
                        <div class="lf_title">{{item.title}}</div>
                    </div>
                    <div class="time">{{item.update_time}}</div>
                </a>
                <a :href="'#/userdetail?id='+item.id+'&name='+name+'&url='+url" v-if="sort === 1&&name =='榜样力量'">
                    <div class="left_title">
                        <div class="point"></div>
                        <div class="lf_title">{{item.title}}</div>
                    </div>
                    <div class="time">{{item.create_time}}</div>
                </a>
                <a :href="'#/ckdetail?id='+item.id+'&name='+name+'&url='+url" v-if="sort === 2">
                    <div class="left_title">
                        <div class="point"></div>
                        <div class="lf_title">{{item.title}}</div>
                    </div>
                    <div class="time">{{item.create_time.slice(0,item.create_time.indexOf(' '))}}</div>
                </a>
            </li>
        </ul>
        <el-empty v-else></el-empty>
   </div>
</template>
<script>
export default {
    name:'commonList',
    props:{
        type:{
            type:Number,
            default:1
        },
        sort:{
            type:Number,
            default:1
        },
        name:{
            type:String,
            default:''
        },
        url:{
            type:String,
            default:'javascript:;'
        },
    },
    data(){
        return{
            list:[]
        }
    },
    mounted(){
        
    },
    watch:{
        name:{
            handler(newval,oldval){
                this.getdata(newval)
            },
            deep:true,
            immediate:true
        }
    },
    methods:{
        getdata(name){
            if(name!='榜样力量'){
                if(this.sort ===1){
                    this.$api.post('getArticleList',{
                            "searchKey":"",
                            "sort":"time",
                            limit:20,
                            "type":name=='最新公告'?'公告':name
                    }).then(res=>{
                        this.list = res.data.list
                    })
                }else{
                    this.$api.post('getProList',{
                            "searchKey":"",
                            "sort":"sort",
                            limit:20,
                            "type":name
                    }).then(res=>{
                        this.list = res.data.list
                    })
                }
            }else{
                this.$api.post('getExampleList',{
                    "sort":"sort",
                    "limit":10 
                }).then(res=>{
                    this.list = res.data.list
                })
            }
            
        }
    }
}
</script>
<style lang="scss" scoped>
    @import  '@/assets/css/common.scss';
</style>